//-------------------------------------------------------------------
//	Copyright (c) 2010-2012 Zhirnov Andrey
//	This file is part of the "UXGEN" project.
//	See copyright notice in "Engine.h".
//-------------------------------------------------------------------

#ifndef _UX_UBO_MANAGER_H
#define _UX_UBO_MANAGER_H

#include "../GLshell/AllGLshellTypes.h"

namespace Engine
{
namespace RenderUtils
{

	//
	// UBO Manager
	//

	class _EXPORT_ CUBOManager : public CEngBaseObject
	{
	private:
		class CUBO
		{
		private:
			GLuint		_uIdent;

			static const gl_buffer::type	_s_eTarget;
			static const gl_usage::type		_s_eUsage;

		public:
			CUBO();
			~CUBO();

			bool  Create(uint uIndex);
			void  Destroy();

			bool  SetData(const void *pData, uint uSize) const;
			bool  Bind(uint uProgram, uint uBlockIndex, uint uIndex) const;

			bool	IsCreated()	const	{ return _uIdent != 0; }
			GLuint	GetIdent()	const	{ return _uIdent; }
		};

	private:
		array< CUBO >	_aUBOs;

	public:
		CUBOManager();
		~CUBOManager();
		
		bool Create(uint uCount);
		void Destroy();

		bool SetData(uint uProgram, uint uIndex, uint uBlockIndex, const void *pData, uint uSize) const;
		bool Bind(uint uProgram, uint uIndex, uint uBlockIndex) const;

		usize GetCount() const	{ return _aUBOs.Count(); }

		// CEngBaseObject //
		virtual void Release();
	};

//-------------------------------------------------------------------

}	// RenderUtils
}	// Engine

#endif	// _UX_UBO_MANAGER_H